package com.example.jacky.android_easeui.utils;

import android.support.design.widget.AppBarLayout;

/**
 * Created by xqc on 2016/9/26.
 * Developer App
 */
public class NativeIncrease {
    public static abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
        /**
         * 展开状态
         */
        public static final int MODE_EXPANDED = 1;
        /**
         * 折叠状态
         */
        public static final int MODE_COLLAPSED = 2;
        /**
         * 中间状态
         */
        public static final int MODE_IDLE = 3;

        private int mCurrentState = MODE_IDLE;

        @Override
        public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
            if (i == 0) {
                if (mCurrentState != MODE_EXPANDED) {
                    onStateChanged(appBarLayout, MODE_EXPANDED);
                }
                mCurrentState = MODE_EXPANDED;
            } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
                if (mCurrentState != MODE_COLLAPSED) {
                    onStateChanged(appBarLayout, MODE_COLLAPSED);
                }
                mCurrentState = MODE_COLLAPSED;
            } else {
                if (mCurrentState != MODE_IDLE) {
                    onStateChanged(appBarLayout, MODE_IDLE);
                }
                mCurrentState = MODE_IDLE;
            }
        }

        public abstract void onStateChanged(AppBarLayout appBarLayout, int state);
    }
}
